package com.unt.javawebunt.dao;

import org.hibernate.Session;
import org.hibernate.Transaction;

import sun.applet.Main;

import com.unt.javawebunt.dto.PatientDTO;
import com.unt.javawebunt.exception.DataAccessLayerException;
import com.unt.javawebunt.util.HibernateUtil;

public class PatientDAOImpl implements IPatientDAO {

	/**
	 * Dao para funciones genericas
	 */
	IGenericDAO<PatientDTO, Long> dao = new GenericDAOImpl<PatientDTO, Long>(
			PatientDTO.class);

	public PatientDTO savePatient(PatientDTO dto) throws DataAccessLayerException {
		
		
		if (dto == null ) {
		//	log.info("INIT - insert = Atributos nulos no permitidos ...");
			throw new DataAccessLayerException();
		}

		//log.info("INIT - insert = Insertando Servicio ...");
		Long id = dao.save(dto);
		dto.setId(id);

		return dto;

		//return null;
	}

	public PatientDTO delete(PatientDTO dto) throws DataAccessLayerException {
		// TODO Auto-generated method stub
		return null;
	}
	
public static void main(String[] args)  {
	
	PatientDTO dtoFoo =  new PatientDTO();
	dtoFoo.setName("tony with session");
	dtoFoo.setAddress("ayacucho 333");
	System.out.println("el dto " + dtoFoo);
//	IPatientDAO dao = new PatientDAOImpl();
	
	Session session = HibernateUtil.getSession();
	Transaction tx = session.beginTransaction();
	
	
//	try {
//		dao.savePatient(dtoFoo);
//	} catch (DataAccessLayerException e) {
//		// TODO Auto-generated catch block
//		e.printStackTrace();
//	}
	
	session.save(dtoFoo);
	tx.commit();
	System.out.println("El dto id es : " + dtoFoo.getId() + dtoFoo.getName());
	
	
	
	
}
}
